#include "distinct_excluded_blocks.h"
#include "utility.h"

using namespace std;

distinct_excluded_blocks::distinct_excluded_blocks()
{

}

distinct_excluded_blocks::~distinct_excluded_blocks()
{

}

void distinct_excluded_blocks::set_max_length(std::string::size_type max_length)
{
    while(bins.size() <= max_length)
        bins.push_back(set<uint64_t>());
}

void distinct_excluded_blocks::add_with_right_checking(const std::string &candidate, string::size_type start_from)
{
    bool found = false;
    for(std::string::size_type len = start_from ; len < candidate.length() ; len++)
    {
        if(bins[len].find(utility::hash_function(utility::get_tail(candidate,len))) != bins[len].end())
        {
            found = true;
            break;
        }
    }
    if(found == false)
    {
        bins[candidate.length()].insert(utility::hash_function(candidate));
    }

}
void distinct_excluded_blocks::add_with_left_checking(const std::string &candidate, string::size_type start_from)
{
    bool found = false;
    for(std::string::size_type len = start_from ; len < candidate.length() ; len++)
    {
        if(bins[len].find(utility::hash_function(utility::get_head(candidate,len))) != bins[len].end())
        {
            found = true;
            break;
        }
    }
    if(found == false)
    {
        bins[candidate.length()].insert(utility::hash_function(candidate));
    }
}
ostream& distinct_excluded_blocks::report(ostream &out)
{
    //typedef map<string::size_type, int> map_type;
    typedef vector< set<uint64_t> > debs_type;
    //cerr << deb_to_length.size() <<endl;

    int n=0;
    for(debs_type::iterator iter = bins.begin() ; iter != bins.end() ; iter++, n++)
    {
        out << n << "," << iter->size() << endl;
    }
    return out;
}
